package com.mc.web.controller.home;

import com.mc.clt.constant.Constants;
import com.mc.clt.domain.CltResult;
import com.mc.clt.domain.HomeTableHeader;
import com.mc.clt.service.ICltService;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.core.page.TableDataInfo;
import com.mc.lab.service.ILabInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("首页")
@RestController
@RequestMapping("/home")
public class HomeReport extends BaseController {
    @Autowired
    private ICltService cltService;
    @Autowired
    private ILabInfoService labInfoService;
    /**
     * 种质资源统计信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('clt:germplasm:query')")
    @GetMapping(value = "/data")
    public AjaxResult germplasmQuery(){
        Map<String,Map> returnMap = new HashMap<String,Map>();
        Map<String,String> germplasMmap = new HashMap<String,String>();
        germplasMmap.put("zk","1");//总库数量
        germplasMmap.put("fk","8");//分库数量
        germplasMmap.put("area","1000");
        germplasMmap.put("species","2323");
        germplasMmap.put("count","3434");
        returnMap.put("germplasm",germplasMmap);
        Map<String,String> specimenMap = new HashMap<String,String>();
        specimenMap.put("count","8");//库数量
        specimenMap.put("area","1000");
        specimenMap.put("type","2323");
        specimenMap.put("specimenCount","3434");
        returnMap.put("specimen",specimenMap);
        Map<String,String> soilMap = new HashMap<String,String>();
        soilMap.put("count","8");//库数量
        soilMap.put("area","1000");
        soilMap.put("type","2323");
        soilMap.put("soilCount","3434");
        returnMap.put("soil",soilMap);
        Map<String,String> collectMap = new HashMap<String,String>();
        collectMap.put("germplasm",String.valueOf(cltService.countCltResult(Constants.GERMPLASM)));//
        collectMap.put("soil","1000");
        collectMap.put("specimen",String.valueOf(cltService.countCltResult(Constants.SPECIMEN)));
        collectMap.put("water","3434");
        returnMap.put("collect",collectMap);
        Map<String,String> machiningMap = new HashMap<String,String>();
        machiningMap.put("count","8");//
        machiningMap.put("throughput","1000");
        returnMap.put("machining",machiningMap);
        Map<String,String> fieldMap = new HashMap<String,String>();
        fieldMap.put("count","8");//
        fieldMap.put("varieties","1000");
        returnMap.put("field",fieldMap);
        Map<String,String> gardenMap = new HashMap<String,String>();
        gardenMap.put("type","8");//
        gardenMap.put("varieties","1000");
        returnMap.put("garden",gardenMap);
        Map<String,String> laboratoryMap = new HashMap<String,String>();
        laboratoryMap.put("type",String.valueOf(labInfoService.countLabInfoForType()));//
        laboratoryMap.put("area",String.valueOf(labInfoService.countLabInfoForArea()));
        returnMap.put("laboratory",laboratoryMap);
        return AjaxResult.success(returnMap);

    }
    @PreAuthorize("@ss.hasPermi('clt:germplasm:query')")
    @GetMapping(value = "/header/{type}")
    public AjaxResult header(@PathVariable String type){
        startPage();
        if(type.equals("collect_germplasm")){
            List<HomeTableHeader> list = new ArrayList<HomeTableHeader>();
            HomeTableHeader homeTableHeader = new HomeTableHeader();
            homeTableHeader.setLabel("采集人");
            homeTableHeader.setValue("nickName");
            list.add(homeTableHeader);
            HomeTableHeader homeTableHeader1 = new HomeTableHeader();
            homeTableHeader1.setLabel("采集编号");
            homeTableHeader1.setValue("germplasmId");
            list.add(homeTableHeader1);
            HomeTableHeader homeTableHeader2 = new HomeTableHeader();
            homeTableHeader2.setLabel("采集时间");
            homeTableHeader2.setValue("collectionTime");
            list.add(homeTableHeader2);
            HomeTableHeader homeTableHeader3 = new HomeTableHeader();
            homeTableHeader3.setLabel("采集地点");
            homeTableHeader3.setValue("location");
            list.add(homeTableHeader3);
            return AjaxResult.success(list);
        }else if(type.equals("collect_specimen")){
            return AjaxResult.success(null);
        }else{
            return AjaxResult.success(null);
        }
    }
    @PreAuthorize("@ss.hasPermi('clt:germplasm:query')")
    @GetMapping(value = "/table/{type}")
    public TableDataInfo type(@PathVariable String type){
        startPage();
        if(type.equals("collect_germplasm")){
            CltResult cltResult = new CltResult();
            cltResult.setCltType(Constants.GERMPLASM);
            return getDataTable(cltService.selectCltResultList(cltResult));
        }else if(type.equals("collect_specimen")){
            return getDataTable(null);
        }else{
            return getDataTable(null);
        }
    }
}
